
THIS_DIR=$(cd $(dirname $0); pwd)
PROJECT_NAME=$(basename ${THIS_DIR})

[ "$TAG_VER" = "" ] && TAG_VER=0.0.0 
[ "$BUILD_NUMBER" = "" ] && BUILD_NUMBER=1

VERSION=${TAG_VER}.${BUILD_NUMBER}

echo "Project: ${PROJECT_NAME}"
echo "Version: ${VERSION}"


echo Create Revision File ...
[ ! -d include ] && mkdir include
echo "//" >  include/revision.h
echo "#define PROJECT_NAME \"${PROJECT_NAME}\""  >>  include/revision.h
echo "#define BOARD_NAME \"${BOARD}\""  >>  include/revision.h
echo "#define VERSION_STRING \"${VERSION}\""  >>  include/revision.h


echo Compile ...
[ ! -d build ] && mkdir build
[ -d build/output ] && rm -rf build/output
mkdir build/output
cd build
cd output
cmake -G Ninja ../.. || exit 1
ninja  || exit 1
cd ..
cd ..


echo Output Files ...
[ -d output ] && rm -rf output
mkdir output
mkdir output/files
[ -f build/output/${PROJECT_NAME}.bin ] && cp build/output/${PROJECT_NAME}.bin output
[ -f build/output/${PROJECT_NAME} ] && cp build/output/${PROJECT_NAME} output
[ -d resource ] && cp -r resource/* output
[ -f output/files/app.info ] && echo "VERSION=${VERSION}">> output/app.info 


echo Build OK



